package main

import (
    "adkr/pkg/config"
    "adkr/pkg/crypto"
    "flag"
    "fmt"
    "log"
)

func main() {
    n := flag.Int("n", 4, "number of nodes")
    bits := flag.Int("bits", 1024, "Paillier key size in bits")
    pubOut := flag.String("pub-out", "paillier_pub.json", "output path for public keys JSON")
    privOut := flag.String("priv-out", "paillier_priv.json", "output path for private keys JSON")
    flag.Parse()

    if *n <= 0 { log.Fatalf("invalid n: %d", *n) }
    if *bits < 512 { log.Fatalf("bits too small: %d", *bits) }

    pubMap := make(map[int]*crypto.PaillierPublicKey)
    privMap := make(map[int]*crypto.PaillierPrivateKey)

    log.Printf("Generating %d Paillier keypairs (bits=%d)...", *n, *bits)
    for i := 0; i < *n; i++ {
        pk, sk, err := crypto.GeneratePaillierKeyPair(*bits)
        if err != nil { log.Fatalf("node %d: %v", i, err) }
        pubMap[i] = pk
        privMap[i] = sk
    }

    if err := config.SavePaillierPublicConfig(*pubOut, pubMap); err != nil {
        log.Fatalf("save pub config: %v", err)
    }
    if err := config.SavePaillierPrivateConfig(*privOut, privMap); err != nil {
        log.Fatalf("save priv config: %v", err)
    }

    fmt.Printf("Wrote public keys to %s\n", *pubOut)
    fmt.Printf("Wrote private keys to %s (protect this file!)\n", *privOut)
}







